package com.itboye.textlieexpters.webview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itboye.textileexpes.adapter.MyOfflineOrderAdapter;
import com.itboye.textileexpes.beans.OfferLineOrderBeans;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.util.MyToast;

public class ListViewAdapter extends BaseAdapter {
	Context context;
	OfferLineOrderBeans beans;
	MyOfflineOrderAdapter adapter;

	public ListViewAdapter(Context context, OfferLineOrderBeans beans) {
		this.context = context;
		this.beans = beans;
		
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return Integer.valueOf(beans.getCount());
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return beans.getList().get(position).getProcessed_order_items()
				.get(0).getItems().size();
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		LinearLayout layout = new LinearLayout(context);
        layout.setOrientation(LinearLayout.VERTICAL);
        adapter=new MyOfflineOrderAdapter(context, beans);
        for (int i = 0; i < adapter.getChildrenCount(position); i++) {
            View view = LayoutInflater.from(context).inflate(
                    R.layout.layout2, null);
            TextView tv = (TextView) view.findViewById(R.id.publish_author_tv);
            int len = beans.getList().get(position).getProcessed_order_items()
    				.size();
    		for (int j = 0; j < len; j++) {
    			tv.setText(beans.getList().get(position)
    					.getProcessed_order_items().get(j).getPlace_origin()
    					+ "");
    			tv.setText(beans.getList().get(position)
    					.getProcessed_order_items().get(j).getContact_name()
    					+ "");
    		}
//            MyToast.toast(beans.getList().get(position).getProcessed_order_items().get(0).getItems().get(position).getId() + "");
//            tv.setText(beans.getList().get(position).getProcessed_order_items().get(0).getItems().get(position).getId() + "");
            layout.addView(view);
        }
        return layout;
	}

}
